/**
 * Copyright (c) 2006, geolabs
 * author : Gérald Fenoy
 *
 * Effect class must be used to dynamicaly modify the graphical representation
 * of an element.
 */

System.require("PeriodicalRunner");
System.require("Styler");

Effect=Class.create({

  appear: function(){
      PeriodicalRunner.run({
	start: arguments[0].start,
	end: arguments[0].limit,
	freq: 200,
	pre: "Styler.setOpacity(System.document.getElementById('"+arguments[0].id+"'),",
	post: ")",
	f: function(){
	    return this.pre+""+arguments[0]+""+this.post;
	}
	});
    },

  fade: function(){
      PeriodicalRunner.run({
	start: arguments[0].limit,
	end: arguments[0].start,
	freq: 200,
	pre: "Styler.setOpacity(System.document.getElementById('"+arguments[0].id+"'),",
	post: ")",
	f: function(){
	    return this.pre+""+(this.start-arguments[0])+""+this.post;
	}
	});
    },

  translate: function(){
      PeriodicalRunner.run({
	start: arguments[0].start,
	end: arguments[0].end,
	top: (arguments[0].top?arguments[0].top:null),
	left: (arguments[0].left?arguments[0].left:null),
	itop: (arguments[0].itop?arguments[0].itop:null),
	ileft: (arguments[0].ileft?arguments[0].ileft:null),
	up: (arguments[0].start>arguments[0].end?1:null),
	freq: 200,
	pre: "System.document.getElementById('"+arguments[0].id+"')",
	pas: 10,
	f: function(){
	    var tmp=-1;
	    if(this.top||this.left){
	      tmp="";
	      if(this.top)
		if(this.up)
		  tmp+=this.pre+".style.top='"+(((this.start-arguments[0])*this.top)/this.pas)+"px';";
		else
		  tmp+=this.pre+".style.top='"+((arguments[0]*this.top)/this.pas)+"px';";
		  
	      if(this.left)
		if(this.up)
		  tmp+=this.pre+".style.left='"+(((this.start-arguments[0])*this.left)/this.pas)+"px';";
		else
		  tmp+=this.pre+".style.left='"+((this.width*arguments[0])/this.pas)+"px';";
	    }
	    else{
	      throw("[_OctoMeta_Effect_translate_error]: You didn't given the arguments to the function call, neither top nor left has been given.");
	      tmp="alert('error')";
	    }
	    return tmp;
	  }
      
	})
	},

  slide: function(){
      PeriodicalRunner.run({
	start: arguments[0].start,
	end: arguments[0].end,
	height: (arguments[0].height?arguments[0].height:null),
	width: (arguments[0].width?arguments[0].width:null),
	iheight: (arguments[0].iheight?arguments[0].iheight:null),
	iwidth: (arguments[0].iwidth?arguments[0].iwidth:null),
	out: (arguments[0].start>arguments[0].end?1:null),
	freq: 200,
	pre: "System.document.getElementById('"+arguments[0].id+"')",
	pas: (arguments[0].pas?arguments[0].pas:10),
	before: function(){
	    var tmp="";
	    if(this.iwidth||this.iheight){
	      if(this.iwidth)
		tmp+=this.pre+".style.width='"+this.iwidth+"px';";
	      if(this.iheight)
		tmp+=this.pre+".style.height='"+this.iheight+"px';";
	    }
	    else
	      tmp="alert('error');"
	    return tmp;
	  },
	f: function(){
	    var tmp=-1;
	    if(this.height||this.width){
	      tmp="";
	      if(this.height)
		if(this.out)
		  tmp+=this.pre+".style.height='"+(((this.start-arguments[0])*this.height)/this.pas)+"px';";
		else
		  tmp+=this.pre+".style.height='"+((arguments[0]*this.height)/this.pas)+"px';";
		  
	      if(this.width)
		if(this.out)
		  tmp+=this.pre+".style.width='"+(((this.start-arguments[0])*this.width)/this.pas)+"px';";
		else
		  tmp+=this.pre+".style.width='"+((this.width*arguments[0])/this.pas)+"px';";
	    }
	    else{
	      throw("[_OctoMeta_Effect_slide_error]: You didn't given the arguments to the function call, neither height nor width has been given.");
	      tmp="alert('error')";
	    }
	    return tmp;
	  }
	});
    }
    


  });

Effect.define({_init: function(){}});
